﻿namespace EFS.Common.Functions
{
	public static class Int32
	{
		/// From string
		public static System.Int32? From(System.String value)
		{
			// try parse
			System.Int32 retValue = 0;
			if (System.Int32.TryParse(value, out retValue))
			{
				return retValue;
			}

			// none
			return null;
		}

		/// From int32?
		public static System.Int32 From(System.Int32? value)
		{
			// check
			if (value.HasValue)
			{
				return value.Value;
			}

			// none
			return 0;
		}

		// get value
		public static System.Int32 Value(System.Int32? value, System.Int32 defaultValue = 0)
		{
			if (null != value && value.HasValue)
			{
				return value.Value;
			}

			return defaultValue;
		}

	}

}